Reliable (TCP)

The key features of reliable packets in DarkNet are:

- Packets arrive in the correct order (first sent, first received).

- Packets always arrive (none are dropped).

- Transfer is slower than unreliable.

Due to the above features, we use TCP for things where we are not concerned too much by the amount of time it takes for a packet to be received, but we are concerned that the packets arrive in the correct order and have a 100% chance of reaching their destination.

Here are some example uses for TCP:

- Sending/receiving in game messages.

- Alerting clients that a client has connected/disconnected.

- Sending/receiving client actions such as: shoot, move left, move right, move forward etc.

TCP transfer can be done in client (mnConnect) and server state (mnStartServer). mnRecvTCP, mnSendTCP and mnSendTCPAll are used to transfer TCP data.

TCP Modes

There are two TCP modes in DarkNet.

1. TM_SIZE: This is enabled by default, is faster than TM_POST_FIX and is compatible with all DarkNet core TCP commands.

When using this TCP mode a 4 byte prefix is included with every packet that you send. This is used by the receiving end to determine the size of the incoming packet. Your application will not receive the prefix, it is used internally by DarkNet.

2. TM_POST_FIX: This is a more limited TCP mode, included for compatibility with other packet schemes. e.g. Using this TCP mode you can communicate with web servers (see HTTP demo code).

When using this TCP mode TCP handshake is automatically disabled (mnDisableTCPHandshake) because the handshaking process cannot function in this TCP mode.

When using this TCP mode a post fix is added to the end of every packet that you send. This is used by the receiving end to indicate the end of a packet. Your application will not receive the postfix, it is used internally by DarkNet. By default the post fix is “\r\n” (C++ escape characters) which allows for HTTP communication. You can change the post fix using mnSetTCPPostfix.




This page is in the following sections:
(1) Networking
(0) DarkNet Help